<template>
 <div>
   <div style="margin-left: 20%;width: 60%;margin-top: 10px">
     <el-form ref="form" :model="user" label-width="80px">
       <el-form-item label="账号：">
         <el-input v-model="user.username"></el-input>
       </el-form-item>
       <el-form-item label="密码：">
         <el-input v-model="user.password" show-password></el-input>
       </el-form-item>
       <el-form-item>
         <el-button type="primary" @click="login">登录系统</el-button>
         <el-button>取消</el-button>
       </el-form-item>
     </el-form>
     <div style="font-size: 10px;color: gray">
       <div style="float: left;margin-left: 30px">
         <router-link class="dv1" to="/register">还没账号，点击注册</router-link>
       </div>
       <div style="float: right;margin-right: 30px">
         <router-link class="dv1" to="/register">忘记密码，点击找回</router-link>
       </div>
     </div>
   </div>

 </div>
</template>

<script setup>
import {ref} from "vue";
import { useRouter } from 'vue-router'
import { useStore } from 'vuex'
import axios from "axios";
const router = useRouter()
const store=useStore()

const user=new ref({})

const login=()=>{
  console.log(user.value);
  axios.post("user/login",user.value).then(res=>{
    if(res.data.code==0){
      //登录 成功
      //记录令牌
      store.commit("setToken",res.data.data);
      //跳转到主页面
      router.push("/index");
    }else {
      alert(res.data.data);
    }
  })
}
</script>

<style scoped>
.dv1{
  color: gray;
}
</style>
